import { http } from './request';
export default {
  // 登陆
  login(params: any) {
    return http.post(`/login`, params);
  },
  // 获取验证码
  sendSms(params: any) {
    return http.post(`/sendSms`, params);
  },
  // 保存头像信息
  saveAvarInfo(params: any) {
    return http.post(`/saveAvarInfo`, params);
  },

  // 获取首页的许愿相关数据
  indexInfo() {
    return http.get(`/api/indexInfo`);
  },
  //获取首页的信息
  getWishClass() {
    return http.get(`/api/getWishClass`);
  },
  //根据类型获取许愿信息
  getWishByClass(params: any) {
    return http.post(`/api/getWishByClass`,params);
  },
  //获取许愿池信息
  getWishPool() {
    return http.get(`/api/getWishPool`);
  },
  //获取隐私政策
  privacyPolicy() {
    return http.get(`/api/privacyPolicy`);
  },
  //获取个人信息
  getUserInfo() {
    return http.get('/api/my/aboutme');
  },

  //删除许愿信息
  deleteWish(params: any) {
    return http.delete(`/api/wishes/deleteByIds`, params);
  },
  //根据id获取许愿信息
  getWish(id: number) {
    return http.get(`/api/wishes/${id}`);
  },
  // 新增许愿信息
  addWish(params: any) {
    return http.post(`/api/wishes/add`, params);
  },
  //编辑许愿信息
  updateWish(params: any) {
    return http.put(`/api/wishes/edit`, params);
  },
  //根据类型获取我的许愿信息
  getWishByType(param: any) {
    return http.get(`/api/wishes/getWishByType?type=${param}`);
  },
  //根据状态获取我的许愿信息
  getWishByStatus(param: any) {
    return http.get(`/api/wishes/getWishByStatus?status=${param}`);
  },
  //立即助力
  doHelp(params: any) {
    return http.post(`/api/wishes/help`, params);
  },
  //我的钱包
  myWallet(params: any) {
    params={

    }
    return http.get(`/api/my/myWallet`);
  },
  //我的钱包
  applyWithDraw(params: any) {
    return  http.post(`/api/my/applyWithDraw`,params);
/*
    let ret =null
    const  promise = new Promise((resolve, reject) =>{
      const data =  http.post(`/api/my/applyWithDraw`,params);
      resolve(data)
    })
    alert(123)
    promise.then(result =>{
      ret= result;
    })
    return ret;*/
  },
  //实名认证
  userAuthentic(params: any) {
  const data =     http.post(`/api/my/userAuthentic`,params);
    console.log(data,"userAuthentic-=========data")
    return data;
  },
  updateUserInfo(params: any) {
    return http.post(`/updateUserInfo`, params);
  },
  loginOut(params: any) {
    return http.post(`/loginOut`, params);
  },
  //我的钱包
  myPartnerRelationship() {
    return http.get(`/api/my/myPartnerRelationship`);
  },
  //我的钱包
  getWxUserInfo(param:any) {
    return http.get(`/getUserInfo?code=`+param);
  },
  // 公众号登陆
  mplogin(params: any) {
    return http.post(`/mpLogin`, params);
  },

  // 公众号登陆
  getwxShareTicket(params: any) {
    return http.get(`/getwxShareTicket?targetUrl=`+params);
  },



};

export function parseTime(time, cFormat) {
  if (arguments.length === 0) {
    return null
  }
  const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}'
  let date
  if (typeof time === 'object') {
    date = time
  } else {
    if ((typeof time === 'string') && (/^[0-9]+$/.test(time))) {
      time = parseInt(time)
    }
    if ((typeof time === 'number') && (time.toString().length === 10)) {
      time = time * 1000
    }
    date = new Date(time)
  }
  const formatObj = {
    y: date.getFullYear(),
    m: date.getMonth() + 1,
    d: date.getDate(),
    h: date.getHours(),
    i: date.getMinutes(),
    s: date.getSeconds(),
    a: date.getDay()
  }
  const time_str = format.replace(/{([ymdhisa])+}/g, (result, key) => {
    const value = formatObj[key]
    // Note: getDay() returns 0 on Sunday
    if (key === 'a') { return ['日', '一', '二', '三', '四', '五', '六'][value] }
    return value.toString().padStart(2, '0')
  })
  return time_str
}



